**------------------------------------------
** Replication materials: "Elite Cues and Economic Policy Attitudes: The Mediating Role of Economic Hardship" by Charlotte Cavaille and Anja Neundorf

** APPENDIX

clear all
capture log close
set more off
set scheme plottig
cd "/Users/aneundorf/Dropbox/Project_CavailleNeundorf/Paper1/Analysis/" // CHANGE DIRECTORY HERE

**----------------------------------------------
** Figure A3: Support for redistribution (1974-2010)
recode PtyAlleg (-1 = .) (1/3 = 3) (4/6 = 1) (7/9 = 2) (10/99 = 99), gen(partyid)

gen Lab = 0 if partyid < . | PTCoarse < . 
replace Lab = 1 if partyid == 1 | PTCoarse == 1


gen Cons = 0 if partyid < . | PTCoarse < . 
replace Cons = 1 if partyid == 3 | PTCoarse == 3

gen Lab_Con = 0 if Lab == 1 
replace Lab_Con = 1 if Cons == 1 


alpha indust42 richlaw2 wealth2 bigbusnn2 redistrb2 , gen(rf) c
egen RF_S = std(rf)
egen MeRF_SL = mean(RF_S) if Lab_Con == 0 , by(year)
egen MeRF_SC = mean(RF_S) if Lab_Con == 1 , by(year)

preserve
collapse RF_S [pw=wtf], by(year)
drop if year == .
drop if RF_S  == . 
tw (scatter RF_S year, xline(1997))  ///
 (lpoly RF_S year , mcol(black) msymbol(smcircle) deg(3)  ///
 xlabel(1986(4)2017, labsize(small) angle(45)) ///
 ylabel(-0.6(0.2)0.6, labsize(small)) ytitle("",size(medsmall)) ///
title("Economic Preferences",size(medium)) xtitle("",size(medium)) legend(off))
graph save "Graphs/FigureA3.gph",replace
graph export "Graphs/FigureA3.pdf",replace
restore


**----------------------------------------------
** Figure A4: Trends in the BSAS for economic preferences: by partisan ship (1986-2017)

preserve
drop if year == .
drop if year == 1994
tw (scatter MeRF_SL year if Lab_Con == 0, xline(1997)) (lpoly RF_S year if Lab_Con == 0 & year < 1997 & year != 1994 , mcol(black) msymbol(smcircle) deg(2) ///
 xlabel(1986(4)2018, labsize(small) angle(45))) ///
 (lpoly RF_S year if Lab_Con == 0 & year >= 1997 , mcol(black) msymbol(smcircle) deg(2) ///
 xlabel(1986(4)2018, labsize(small) angle(45))) ///
(scatter MeRF_SC year if Lab_Con == 1) (lpoly RF_S year if Lab_Con == 1 & year < 1997, mcol(red) msymbol(smcircle) deg(2) ///
 xlabel(1986(4)2018, labsize(small) angle(45)) ) ///
 (lpoly RF_S year if Lab_Con == 1 & year >= 1997, mcol(red) msymbol(smcircle) deg(2) ///
 xlabel(1986(4)2018, labsize(small) angle(45)) , ///
 ylabel(-1(0.2)0.6, labsize(small)) ytitle("",size(medsmall)) ///
title("Economic Preferences",size(medium)) xtitle("",size(medium)) legend(order( 1 "Labour Party" 4 "Conservative party" )))
graph save "Graphs/FigureA4.gph",replace
graph export "Graphs/FigureA4.pdf",replace

restore

**----------------------------------------------
** Figure A5: Time-varying predicted probabilities of attitudinal stability (incl. 95% C.I.)


use "Data/transprobs_general.dta", clear 

* Time
tab time
recode time (1=1993) (2=1995) (3=1997) (4=2000) (5=2004) (6=2007)
tab time,m

*rename ideol1 ideol_1

foreach i  of any cons lib cent {

bysort ideol_1 time: egen time_ideol_`i'  = mean(`i') 
gen time_ideol_`i'_p = time_ideol_`i'*100
}

foreach i  of any cons lib cent {
bysort  ideol_1 time: egen time_ideol_`i'_se = mean(`i'_se) 
gen time_`i'_up = (time_ideol_`i' + time_ideol_`i'_se*2) * 100
gen time_`i'_low = (time_ideol_`i' - time_ideol_`i'_se*2) * 100
}

* Ideol: 1=cons, 2=lib, 3=cent


 * Ideol: stability over time
 
twoway(rarea time_lib_up time_lib_low time if ideol_1==2, col(gs5) lc(white) fi(30)) ///
(rarea time_cons_up time_cons_low time if ideol_1==1, col(gs2) lc(gs15) fi(30)) ///
(line time_ideol_lib_p time if ideol_1==2, col(gs2) lw(medthick) lp(solid)) ///
(line time_ideol_cons_p time if ideol_1==1, col(gs6) lw(medthick ) lp(shortdash))  , ///
ytitle(Ideology stability  (in %), size(medium)) ///
xtitle("Survey year", size(medium)) xline(1997) ///
  ylabel(50(10)105,labsize(medsmall)) ylabel(, nogrid) xlabel(1993 1995 1997 2000 2004 2007, valuelabel labsize(medium)) ///
legend(order(3 4) lab(3 "Left-wing in t-1 & t") lab(4 "Right-wing in t-1 & t")) legend(region (lc(white)) r(2) pos(5) ring(0) size(medium)) ///
scheme(plottig) graphregion(fcolor(white)) 
graph save "Graphs/FigureA5.gph",replace
graph export "Graphs/FigureA5.pdf",replace


**----------------------------------------------
** Figure A6: Time-varying predicted probabilities of left-wing dealignment (left-wing in t1; centrist in t) by political Interest and partisanship (incl. 95% C.I.) 

use "Data/transprobs_polint.dta", clear 

* Time
tab time
recode time (1=1993) (2=1995) (3=1997) (4=2000) (5=2004) (6=2007)
tab time,m

*rename ideol1 ideol_1

foreach i  of any cons lib cent {

bysort ideol_1 time polint: egen time_ideol_`i'  = mean(`i') 
gen time_ideol_`i'_p = time_ideol_`i'*100
}

foreach i  of any cons lib cent {
bysort  ideol_1 time polint: egen time_ideol_`i'_se = mean(`i'_se) 
gen time_`i'_up = (time_ideol_`i' + time_ideol_`i'_se*2) * 100
gen time_`i'_low = (time_ideol_`i' - time_ideol_`i'_se*2) * 100
}


* Ideol: 1=lib; 2=con; 3=cent

* Liberal dealalignment 

* Ideol: dealignment over time
 
twoway(rarea time_cent_up time_cent_low time if ideol_1==1 & polint==0, col(gs5) lc(white) fi(30)) ///
(rarea time_cent_up time_cent_low time if ideol_1==1 & polint==1, col(gs2) lc(gs15) fi(30)) ///
(line time_ideol_cent_p time if ideol_1==1 & polint==0, lw(medthick) lp(shortdash) lc(black)) ///
(line time_ideol_cent_p time if ideol_1==1 & polint==1, lw(medthick ) lp(solid) lc(gs6))  , ///
ytitle(% of Leftist dealignemnt (Centrist in t), size(medium)) ///
xtitle("") xline(1997)  ///
  ylabel(0(10)40,labsize(medsmall)) ylabel(, ) xlabel(1993 1995 1997 2000 2004 2007, valuelabel labsize(medium)) ///
title("A. Political interest", size(large)) legend(order(3 4) lab(3 "Low") lab(4 "High")) legend(region (lc(white)) r(2) pos(1) ring(0) size(medsmall)) name(polint, replace) ///
 graphregion(fcolor(white)) 
 
 
 *** Load data  ****

use "Data/transprobs_pid.dta", clear 

* Time
tab time
recode time (1=1993) (2=1995) (3=1997) (4=2000) (5=2004) (6=2007)
tab time,m

*rename ideol1 ideol_1

foreach i  of any cons lib cent {

bysort ideol_1 time pid: egen time_ideol_`i'  = mean(`i') 
gen time_ideol_`i'_p = time_ideol_`i'*100
}

foreach i  of any cons lib cent {
bysort  ideol_1 time pid: egen time_ideol_`i'_se = mean(`i'_se) 
gen time_`i'_up = (time_ideol_`i' + time_ideol_`i'_se*2) * 100
gen time_`i'_low = (time_ideol_`i' - time_ideol_`i'_se*2) * 100
}


* Ideol:1=con 2=centr 3=lib


* Liberal dealalignment 

* Ideol: dealignment over time
* PID: 1=Lab 2=Con 3=None

 
twoway(rarea time_cent_up time_cent_low time if ideol_1==3 & pid==2, col(gs5) lc(white) fi(30)) ///
(rarea time_cent_up time_cent_low time if ideol_1==3 & pid==1, col(gs2) lc(gs15) fi(30)) ///
(line time_ideol_cent_p time if ideol_1==3 & pid==2, lw(medthick) lp(shortdash) lc(black)) ///
(line time_ideol_cent_p time if ideol_1==3 & pid==1, lw(medthick ) lp(solid) lc(gs6))  , ///
ytitle(% of Leftist dealignemnt (Centrist in t), size(medium)) ///
xtitle("")  ///
  ylabel(0(10)40,labsize(medsmall)) ylabel(, ) xlabel(1993 1995 1997 2000 2004 2007, valuelabel labsize(medium))xline(1997)  ///
title("B. Initial Partisanship", size(large)) legend(order(3 4) lab(3 "Conservatives") lab(4 "Labour"))legend(region (lc(white)) r(2) pos(1) ring(0) size(medsmall)) name(pid, replace) ///
 graphregion(fcolor(white)) 
 
graph combine polint pid, scheme(s2mono) graphregion(fcolor(white)) 
graph save "Graphs/FigureA6.gph",replace
graph export "Graphs/FigureA6.pdf",replace

**-------------------------------------------------------------
** Figure A10: Distribution of three additive index by classes of economic policy preferences

use "Data/classifications.dta", clear 

* Sum of items
tab1 opsoc_a opsoc_c opsoc_b opsoc_d opsoc_e opsoc_f
gen sum_econ = opsoc_a + opsoc_c + opsoc_b + opsoc_d + opsoc_e + opsoc_f
tab sum_econ

sum sum_econ
sum sum_econ if ideol_==1
sum sum_econ if ideol_==2
sum sum_econ if ideol_==3

twoway(kdensity sum_econ if ideol_==3) ///
(kdensity sum_econ if ideol_==1) ///
(kdensity sum_econ if ideol_==2), ///
ytitle(, size(medium)) xline(16.2, lc(red)) ///
xtitle("Sum of economic scale", size(medium))  ///
  ylabel(,labsize(small)) ylabel(, nogrid) xlabel( ,labsize(small)) ///
legend(lab(1 "Leftist") lab(2 "Centrist") lab(3 "Rightist") row(1) region (lc(white)  )) ///
scheme(s2mono) graphregion(fcolor(white))
graph save "Graphs/FigureA10.gph",replace
graph export "Graphs/FigureA10.pdf",replace 


**----------------------------------------------
** Figure A11: Predicted economic preferences by political Interest and partisanship (95% C.I.)

use "Data/BHPS_atleast1validresponses.dta", clear

*** drop if less than 4 of the 6 are answered

alpha opsoc_a_rev opsoc_c_rev opsoc_b_rev opsoc_d_rev opsoc_e_rev opsoc_f_rev, gen(miss) min(6)
alpha opsoc_a_rev opsoc_c_rev opsoc_b_rev opsoc_d_rev opsoc_e_rev opsoc_f_rev, gen(miss2) min(4)
drop if miss2 >= . 

** compute DV

alpha opsoc_a_rev  opsoc_c_rev opsoc_b_rev opsoc_d_rev opsoc_e_rev opsoc_f_rev, gen(econ_I)
egen econ_I_S = std(econ_I)


** compute partisanship 

egen pid_1991 = max(cond(year == 1991, pid3cat, .)), by(pid)
egen pid_1993 = max(cond(year == 1993, pid3cat, .)) , by(pid)
egen pid_1995 = max(cond(year == 1995, pid3cat, .)) , by(pid)
egen pid_1997 = max(cond(year == 1997, pid3cat, .)) , by(pid)


gen lab = 0 if pid_1991 < .  | pid_1993 < .  | pid_1995 < . 
replace lab = 1 if pid_1991 == 2 | pid_1993 == 2 | pid_1995 == 2

gen con = 0 if pid_1991 < .  | pid_1993 < .  | pid_1995 < . 
replace con = 1 if pid_1991 == 1 | pid_1993 == 1 | pid_1995 == 1

tab lab con
gen lab2 = lab
replace lab = 0 if con == 1 & lab2 == 1
replace con = 0 if con == 1 & lab2 == 1
drop lab2

gen pid_new = 1 if con == 1 
replace pid_new = 2 if lab == 1
replace pid_new = 0 if lab == 0 & con == 0

label define pid_newL 0 "Neither" 1 "Conservative" 2 "Labour"
label values pid_new pid_newL

*** compute political interest 

egen polint_ter = mean(polint) , by(pid)
sum polint_ter, de


tab pid_new if year < 1997


gen switch = 0 if pid_new != .
replace switch = 1 if pid_new == 1 & pid_1997 == 2
replace switch = 2 if pid_new == 0 & pid_1997 == 2
tab switch econideo_cat if year == 1997 & pid_1997 == 2, row col
tab switch econideo_cat if year == 1997 , row col


tab pid_1997 pid_new if year == 1997 

reg econ_I_S i.year##i.pid_new##c.polint_ter  , cluster(pid)

margins , at(year=(1991 1993 1995 1997 2000 2004 2007) polint_ter=1 pid_new == 2) ///
at(year=(1991 1993 1995 1997 2000 2004 2007) polint_ter=3.25 pid_new == 2) 
 marginsplot, plot1opts(lpattern(dash) lw(medium) lc(gs9) mc(gs9)) /// 
	plot2opts(lpattern(solid) lw(medthick) lc(black) ms(triangle) mc(black)) /// 
	xlabel( ,  angle(horizontal)labsize(small)) ///
	ylabel(-1.3(0.1)-0.1	, labsize(small)) xline(1996)  ///
	ytitle("Predicted economic preferences", size(medium)) 	xtitle("")  ///
	legend(order(3 "Low political interest (P10)" 4 "High political interest (P90)") region(lcolor(wite)) pos(5) ring(0) size(medsmall)) ///
scheme(plottig) graphregion(fcolor(white)) title("A. Political interest -- Labour Party ", size (large)) name(polint, replace)
graph save "pol_int_L.gph", replace

margins , at(year=(1991 1993 1995 1997 2000 2004 2007) polint_ter=1 pid_new == 1) ///
at(year=(1991 1993 1995 1997 2000 2004 2007) polint_ter=3.25 pid_new == 1) 
 marginsplot, plot1opts(lpattern(dash) lw(medium) lc(gs9) mc(gs9)) /// 
	plot2opts(lpattern(solid) lw(medthick) lc(black) ms(triangle) mc(black)) /// 
	xlabel( ,  angle(horizontal)labsize(small)) ///
	ylabel(0.1(0.1)1.3	, labsize(small)) xline(1996)  ///
	ytitle("", size(medium)) 	xtitle("")  ///
		legend(order( 3 "Low political interest (P10)" 4 "High political interest (P90)") region(lcolor(wite)) pos(2) ring(0) size(medsmall)) ///
scheme(plottig) graphregion(fcolor(white)) title("B. Political interest -- Conservative Party ", size (large)) name(polint, replace)
graph save "pol_int_C.gph", replace



graph combine "pol_int_L.gph" "pol_int_C.gph" , col(2)
graph save "Graphs/FigureA11.gph", replace
graph export "Graphs/FigureA11.pdf", replace


**-------------------------------------------------------------
** Table A8: OLS regression with individual fixed effects

gen time2 = time
replace time2 = 0 if year == 1991 
sort pid time2
xtset pid time2
gen inc_log2 = l.inc_log

capture erase "Graphs/TableA8.xls"
capture erase "Graphs/TableA8.txt"


* Model 1: everyone, FE, subjective
xtreg econ_I_S fisit jobsec_cat , fe
estat ic
estimate store M1
outreg2  using "Graphs/TableA8.xls", ///
			bracket bdec(3) sdec(3) append
			
* Model 2: everyone, FE, unemp and income  
xtreg econ_I_S c.inc_log i.unemp , fe
estat ic
estimate store M2
outreg2  using "Graphs/TableA8.xls", ///
			bracket bdec(3) sdec(3) append
		
* Model 3: everyone, sub and obj (can;t have both measures of income tin there, not enough unemp drops out)
xtreg econ_I_S fisit jobsec_cat c.inc_log i.unemp, fe
estat ic
estimate store M3
outreg2  using "Graphs/TableA8.xls", ///
			bracket bdec(3) sdec(3) append
					
* Model 4: with year FE 
xtreg econ_I_S fisit jobsec_cat c.inc_log i.unemp i.year , fe
estat ic
estimate store M4
outreg2  using "Graphs/TableA8.xls", ///
			bracket bdec(3) sdec(3) append
			
* Model 5: with year FE and age 
xtreg econ_I_S fisit jobsec_cat c.inc_log i.unemp i.year c.age##c.age , fe
estat ic
estimate store M5
outreg2  using "Graphs/TableA8.xls", ///
bracket bdec(3) sdec(3) append


* Model 5: with year FE and age  labour only 
xtreg econ_I_S fisit jobsec_cat c.inc_log i.unemp i.year c.age##c.age if lab == 1 , fe
estat ic
estimate store M6
outreg2  using "Graphs/TableA8.xls", ///
bracket bdec(3) sdec(3) append


**-------------------------------------------------------------
** Figure A12: Change in Gender values (centrist in t; left-wing or right-wing in t-1)

use "Data/transprobs_gender.dta", clear

* Liberal realalignment 
foreach i  of any cen {
twoway(rarea time_finsit_`i'_up time_finsit_`i'_low time if finsit_drop==2 & ideol_1==3, col(gs3) lc(white) fi(30)) ///
(rarea time_finsit_`i'_up time_finsit_`i'_low time if finsit_drop==3& ideol_1==1, col(gs5) lc(gs15) fi(30)) ///
(line time_finsit_`i'_p time if finsit_drop==2& ideol_1==3, lw(medthick) lp(shortdash) lc(black)) ///
(line time_finsit_`i'_p time if finsit_drop==3 & ideol_1==1, lw(medthick ) lp(solid) lc(gs6))  , ///
xtitle("", size(medium))  ytitle("Gender value dealignment (Centrist in t; in %)", size(medium)) ///
  ylabel(0(5)25,valuelabel labsize(medsmall)) ylabel(, ) xlabel(1993 1995 1997 1999 2001 2003 2005 2007, valuelabel labsize(medsmall)) xline(1997) ///
 legend(region (lc(white))) legend(order(3 4) ///
lab(3 "Liberal in t-1") lab(4 "Conservative in t-1") region(lcolor(white)) pos(1) ring(0) size(medsmall)) ///
scheme(plottig) graphregion(fcolor(white))
}

   graph save "Graphs/FigureA12.gph", replace
  graph export "Graphs/FigureA12.pdf", replace
